

#coding=utf-8

# 进程之间是不共享内存的

from multiprocessing import Process, Queue

import time

import os

count = 10

def modifycount(nums):

    #获取当前线程对象

    for index in range(count):

        nums.append(index)

        print("1",nums)

        # print('%s,修改nums'%(nums))

        time.sleep(0.1)

def printcount(nums):

    #获取当前线程对象


    for index in range(count):

        print("2", nums)
        # print('%s,nums=%s'%(nums))

        time.sleep(0.1)

if __name__ == "__main__":

    print('pid=%d'%os.getpid())

    nums=[]

    #创建线程，此线程修改全局变量

    t = Process(target=modifycount, args=(nums,))

    t2 = Process(target=printcount, args=(nums,))

    t.start()

    t2.start()

    t.join()

    t2.join()

    print('主线程结束,nums=%s'%(nums))